const express = require("express");
const router = express.Router();

// 导入子路由
const userRoutes = require("./user");
const articleRoutes = require("./article");

// 健康检查路由
router.get("/health", (req, res) => {
  res.status(200).json({
    status: "OK",
    timestamp: new Date().toISOString(),
    uptime: process.uptime(),
    environment: process.env.NODE_ENV || "development",
  });
});
router.post("/health", (req, res) => {
  res.status(200).json({
    ...req.body,
  });
});

// API版本路由
// 用户路由
router.use("/users", userRoutes);

// 文章路由
router.use("/article", articleRoutes);

// 404处理（Express 5 / path-to-regexp v6：不要使用 '*' 通配）
router.use((req, res) => {
  res.status(404).json({
    success: false,
    message: `Route ${req.originalUrl} not found`,
    timestamp: new Date().toISOString(),
  });
});

module.exports = router;
